﻿#region Copyright (c) 2000-2008 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{       AgDataGrid                                 }
{                                                                   }
{       Copyright (c) 2000-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2008 Developer Express Inc.

using System.IO;
using System.Resources;
using System.Windows;
using System.Windows.Markup;
namespace DevExpress.AgMenu.ElementStyles {
	public class dxElementStyles {
		public static readonly DependencyProperty StyleNameProperty = DependencyProperty.RegisterAttached("StyleName", typeof(string), typeof(dxElementStyles),
			new PropertyMetadata(delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) {
			StyleNameChanged(d);
		}));
		static ResourceDictionary elementStyleDictionary;
		static dxElementStyles() {
			elementStyleDictionary = GetElementStyleDictionary();
		}
		public static Style GetStyle(string styleName) {
			return (Style)elementStyleDictionary[styleName];
		}
		public static string GetStyleName(DependencyObject o) {
			return (string)o.GetValue(StyleNameProperty);
		}
		public static void SetStyleName(DependencyObject o, string value) {
			o.SetValue(StyleNameProperty, value);
		}
		static ResourceDictionary GetElementStyleDictionary() {
			string baseName = typeof(dxElementStyles).Assembly.FullName;
			baseName = baseName.Substring(0, baseName.IndexOf(",")) + ".g";
			ResourceManager manager = new ResourceManager(baseName, typeof(dxElementStyles).Assembly);
			UnmanagedMemoryStream stream = manager.GetStream("themes/dxelementstyles.xaml");
			string s = (new StreamReader(stream)).ReadToEnd();
			s = s.Remove(0, s.IndexOf('<'));
			return XamlReader.Load(s) as ResourceDictionary;
		}
		static void StyleNameChanged(DependencyObject o) {
			o.SetValue(FrameworkElement.StyleProperty, elementStyleDictionary[o.GetValue(StyleNameProperty)]);
		}
	}
}
